package com.art.sunflower.service.impl;

import com.art.sunflower.exception.NullCooperationException;
import com.art.sunflower.mapper.CooperationMapper;
import com.art.sunflower.pojo.Cooperation;
import com.art.sunflower.service.CooperationService;
import com.art.sunflower.util.MyPageInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CooperationServiceImpl implements CooperationService {
    @Resource
    CooperationMapper cooperationMapper;

    @Override
    public int insert(Cooperation cooperation) {
        return cooperationMapper.insert(cooperation);
    }

    @Override
    public int update(Cooperation cooperation) {
        return cooperationMapper.update(cooperation);
    }

    @Override
    public int delete(int id) {
        return cooperationMapper.delete(id);
    }

    @Override
    public Cooperation selectOne(int id) {
        return cooperationMapper.selectOne(id);
    }

    @Override
    public List<Map<String, Object>> listIdName() {
        return cooperationMapper.listIdName();
    }

    @Override
    public MyPageInfo listAll(Integer pageSize, Integer pageNo) throws NullCooperationException {
        //需要进行分页
        PageHelper.startPage(pageNo, pageSize);
        List<Map<String, Object>> cooperation = cooperationMapper.listAll();
        if (cooperation.size() == 0)
            throw new NullCooperationException();
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(cooperation);
        return new MyPageInfo(pageInfo);
    }
}
